package pool;

import java.net.InetSocketAddress;
import java.net.Socket;

/**
 * @author zy.du
 * @date 2020/11/11 2:18 PM
 */
public class ConnectionFactory {

    public static Connection create(InetSocketAddress socketAddress) throws RuntimeException {
        try {
            Socket sock = new Socket();
            sock.setReuseAddress(true);
            sock.setSoTimeout(30000);
            sock.connect(socketAddress, 5000);
            return new Connection(sock, socketAddress);
        } catch (Exception e) {
            throw new RuntimeException("connect to server " + socketAddress.getAddress().getHostAddress() + ":" + socketAddress.getPort() + " fail, emsg:" + e.getMessage());
        }
    }
}
